Skip to content

Document Euler method accuracy comparison - #111

Open
pruthvirajgojare-source wants to merge 1 commit into
S-AI-Projects:masterfrom
pruthvirajgojare-source:R23-T047
Open

pruthvirajgojare-source wants to merge 1 commit into
S-AI-Projects:masterfrom
pruthvirajgojare-source:R23-T047

Conversation

@pruthvirajgojare-source

@pruthvirajgojare-source pruthvirajgojare-source commented Nov 21, 2026 •

Copy link
Copy Markdown

Description

Documents the error behavior of explicit Euler alongside modified Euler and classical RK4 for dy/dx = y, y(0) = 1 on [0, 1]. This makes the accuracy-versus-step-size tradeoff clearer for learners and adds a doctest that demonstrates the methods' observed convergence orders.

Related Issue

None identified.
Fixes: N/A (no related issue)

Type of Change

  • Bug Fix
  • New Feature
  • UI/UX Improvement
  • Performance Improvement
  • Tests
  • Documentation
  • Refactoring / Maintenance
  • CI/CD

Changes Made

  • Added an error-order comparison and doctest to maths/euler_method.py.
  • Added work/R23-T047/compare_test.py to exercise the three solvers on 11 shared inputs, including the requested step sizes 0.1, 0.05, and 0.025, and to benchmark them on the same cases.
  • Added work/R23-T047/COMPARE.md with API differences, error results, timings, and a beginner recommendation.

For the requested initial-value problem, the measured observed orders were 0.9533 (explicit Euler), 1.9591 (modified Euler), and 3.9550 (RK4), consistent with O(h), O(h^2), and O(h^4).

h Explicit Euler error Modified Euler error RK4 error
0.1 0.124539368359 0.004200981851 2.084323879e-6
0.05 0.064984123315 0.001090774104 1.358027100e-7
0.025 0.033217990069 0.000277884088 8.666190432e-9

Screenshots / Recordings

Not applicable; this PR changes algorithm documentation and test evidence, not the UI.

Testing

  • uv run pytest work/R23-T047/compare_test.py — passed, 12 tests.
  • uv run pytest maths/euler_method.py maths/euler_modified.py maths/numerical_analysis/runge_kutta.py --doctest-modules — passed, 3 modules.
  • uv run python -m doctest -v maths/euler_method.py — passed, 11 examples.
  • uvx ruff check maths/euler_method.py work/R23-T047/compare_test.py — passed.
  • uvx ruff format --check maths/euler_method.py work/R23-T047/compare_test.py — passed.

Checklist

  • I have tested my changes locally.
  • I have added or updated tests, if needed.
  • I have updated documentation, if needed.
  • I have followed the project's coding guidelines.
  • I have run the relevant tests and checks.
  • I have addressed previous review feedback, if applicable (none received yet).

Additional Notes

On the tested macOS arm64 / Python 3.15.0rc3 free-threading environment, the median times were 6.03 us/solve for explicit Euler, 12.49 us/solve for modified Euler, and 17.72 us/solve for RK4. These timings are machine-dependent. Explicit Euler is recommended as a beginner's starting point for its simple update; the other two methods illustrate higher accuracy at additional per-step cost.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant